#include <allegro.h>
#include <time.h>
#include "bonus_1bis.h"




int main ()
{
BITMAP* plaque_s;
BITMAP* plaque_mb;
BITMAP* plaque_p;
BITMAP* plaque_6_v;
BITMAP* buffer;
BITMAP* curseur;
BITMAP* background;
//BITMAP* rep1;
int s_check_1=0,s_check_2=0, sparrow=0, c_s=0;
int mb_check_1=0, mb_check_2=0, mboss=0, c_mb=0;
int p_check_1=0, p_check_2=0, pirate=0, c_p=0;
int score=0, compteur ;
Rebecca R;

/* General initialization function */
allegro_init();

install_keyboard() ;
if (install_keyboard() == -1)
{
allegro_message("Error! %s", allegro_error);
return (-1);
}

install_mouse() ;

if (install_mouse () == -1)
{
allegro_message("Erreur ! %s", allegro_error) ;

return -1 ;
}

set_color_depth(32);

if (set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0) != 0)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
return (1);
}

//rep1 = load_bitmap("rep1.bmp", NULL) ;

/////////////////////////////////////////////////////////
buffer = create_bitmap(SCREEN_W, SCREEN_H) ;
load_Rebecca(&R);
load_plaques( &plaque_s, & plaque_mb, &plaque_p, &plaque_6_v);
load_cursor(&curseur);
background = load_bitmap("nuit.bmp", NULL) ;
set_mouse_range(0, 0, SCREEN_W-curseur->w,SCREEN_H-curseur->h);
init_Rebecca(&R);
while(!key[KEY_ESC] )
{
clear_bitmap(buffer) ;
draw_sprite(buffer, background, 0, 0);
draw_sprite(buffer, plaque_6_v, p1, y_up1);
draw_sprite(buffer, curseur, mouse_x, mouse_y);

//sparrow 1
if (mouse_x < p11 && mouse_x > p1 && mouse_y < y_up2 && mouse_y > y_up1 && (mouse_b & 1))
{
	draw_sprite(buffer, plaque_s, p1, y_up1);
	s_check_1=1;c_s++;
}
//pirate 1
 else if (mouse_x < p22 && mouse_x > p2 && mouse_y < y_up2 && mouse_y > y_up1 && (mouse_b & 1))
{
	draw_sprite(buffer, plaque_p, p2, y_up1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	p_check_1=1;c_p++;

}
//mb 1
 else if (mouse_x < p33 && mouse_x > p3 && mouse_y < y_up2 && mouse_y > y_up1 && (mouse_b & 1))
{
	draw_sprite(buffer, plaque_mb, p3, y_up1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	mb_check_1=1;c_mb++;

}
//mb 2
else if (mouse_x < p11 && mouse_x > p1 && mouse_y < y_down2 && mouse_y > y_down1 && (mouse_b & 1))
{
	draw_sprite(buffer, plaque_mb, p1, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	mb_check_2=1;c_mb++;
}
//pirate 2
 else if (mouse_x < p22 && mouse_x > p2 && mouse_y < y_down2 && mouse_y > y_down1 && (mouse_b & 1))
{
	draw_sprite(buffer, plaque_p, p2, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	p_check_2=1;c_p++;

}
//sparrow 2
 else if (mouse_x < p33 && mouse_x > p3 && mouse_y < y_down2 && mouse_y > y_down1 && (mouse_b & 1))
{
	draw_sprite(buffer, plaque_s, p3, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	s_check_2=1;c_s++;

}
//sparrow check
if ((s_check_1==1) && (s_check_2==1))
{
	draw_sprite(buffer, plaque_s, p1, y_up1);
	draw_sprite(buffer, plaque_s, p3, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
        sparrow=1;
}
// pirate check
if ((p_check_1==1) && (p_check_2==1))
{
	draw_sprite(buffer, plaque_p, p2, y_up1);
	draw_sprite(buffer, plaque_p, p2, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	pirate=1;
}
//mb check
if ((mb_check_1==1) && (mb_check_2==1))
{
	draw_sprite(buffer, plaque_mb, p3, y_up1);
	draw_sprite(buffer, plaque_mb, p1, y_down1);
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
	mboss=1;
}


//final check
if ( sparrow == 1 && pirate == 1 && mboss == 1)
{
	//etat = 0;
	score =  c_s + c_mb + c_p;
	textprintf(buffer, font, 100, 400, makecol(255,255,255 ), "FELICITATIONS VOTRE SCORE EST ** %i **",score);
	/////////////////////	
			compteur=0;
			draw_Rebecca_bonus(&R,buffer,compteur);
			////////////////////		
	draw_sprite(buffer, curseur, mouse_x, mouse_y);
            /*if (key[KEY_R])
     		{etat=1;}
	    else if (key[KEY_Q]) etat = 0;*/
}

vsync();

blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;

}
destroy_plaques( &plaque_s, &plaque_mb, &plaque_p, &plaque_6_v);
destroy_cursor(&curseur);
destroy_Rebecca(&R);
return 0;
}
END_OF_MAIN();

